import 'package:convergence_media/di/di.dart';
import 'package:convergence_media/features/user/entities/nav_user_model.dart';
import 'package:isar/isar.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'nav_user_repository.g.dart';

@riverpod
NavUserRepository navUserRepository(NavUserRepositoryRef ref) =>
    NavUserRepository(isar: ref.watch(appIsarProvider));

/// {@template base_user_repository}
/// 存储用户信息
/// {@endtemplate}
class NavUserRepository {
  /// {@macro base_user_repository}
  const NavUserRepository({
    required Isar isar,
  }) : _isar = isar;

  final Isar _isar;

  /// 保存用户信息
  Future<void> saveNavUser(NavUserModel userInfo) =>
      _isar.writeTxn(() => _isar.navUserModels.put(userInfo));

  /// 读取用户信息
  Future<NavUserModel?> readNavUser(Id id) => _isar.navUserModels.get(id);
}
